﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace project
{
    public partial class SupplierManage : Form
    {
        public SupplierManage()
        {
            InitializeComponent();
        }

        private void Form3_Load(object sender, EventArgs e)
        {
            InitData();
        }
        public void InitData()
        {
            string sql = "select * from Supplier";
            DataTable dt = DBHelper.GetTable(sql);
            this.dataGridView1.DataSource = dt;
            this.dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void Form3_FormClosing(object sender, FormClosingEventArgs e)
        {

        }

        private void buttonAdd_Click(object sender, EventArgs e)
        {
            SupplierAdd supplierAdd = new SupplierAdd(this);
            supplierAdd.ShowDialog();
        }

        private void buttonUpdate_Click(object sender, EventArgs e)
        {
            string id= this.dataGridView1.CurrentRow.Cells[0].Value.ToString();
            SupplierUpdate supplierUpdate = new SupplierUpdate(id,this);
            supplierUpdate.ShowDialog();
        }

        private void buttonDelete_Click(object sender, EventArgs e)
        {
            string id=this.dataGridView1.CurrentRow.Cells[0].Value.ToString();
            string sql = "Delete from Supplier where Id="+id;
            int re= DBHelper.ExecuteNonQuery(sql);
            if (re>0)
            {
                MessageBox.Show("删除成功");
                InitData();
            }
        }
    }
}
